﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.Square.Show;

namespace University.Workshop.Presentation.Square.Show
{
    /// <summary>
    /// Interaction logic for PageFirstStepShowSquare.xaml
    /// </summary>
    public partial class PageFirstStepShowSquare : Page,IFirstStepForShowSquare
    {
        private Presenters.Square.Show.PresenterShowSquare pShowSquare;

        public PageFirstStepShowSquare(PresenterShowSquare pShowSquare)
        {
            InitializeComponent();
            this.pShowSquare = pShowSquare;
            App.Current.MainWindow.Title = "UIMostrarManzano";
        }

        public Model.Square SquareToShow
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                SquareNameTxBx.Text = value.SquareId;
                SquareCommentTxBx.Text = value.Comment;
            }
        }

        public ICollection<Model.Allotment> AllotmentsToShow
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {

            }
        }

        public string UbicationCroquisSquareToShow
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                    if (File.Exists(value))
                    {
                        CroquisUbicationTxBx.Text = value;
                        BitmapImage image = new BitmapImage();
                        using (FileStream stream = File.OpenRead(value))
                        {
                            image.BeginInit();
                            image.StreamSource = stream;
                            image.CacheOption = BitmapCacheOption.OnLoad;
                            image.EndInit(); // load the image from the stream
                        } // close the stream
                        SquareImageImg.Source = image;
                    }
                    else
                    {

                        CroquisUbicationTxBx.Text = string.Empty;
                    }

            }
        }

        public void Update()
        {

        }

        public void GoNextPage()
        {
            pShowSquare.GoStepTwo();
        }

        public void GoBackPage()
        {

        }

        private void ShowImageSquareBtn_Click(object sender, RoutedEventArgs e)
        {
            pShowSquare.ShowImageSquare();
        }
    }
}
